package com.basin.common.rabbitmq.support;

import com.basin.common.rabbitmq.template.SendMsgTemplate;
import jakarta.annotation.Resource;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * @author: Sam ZHONG | sammy1997@aliyun.com
 */
@Component
public class RabbitmqProducer {
    @Resource
    public RabbitTemplate rabbitTemplate;

    public <T> void send(SendMsgTemplate<T> msgTemplate) {
        T message = msgTemplate.getMessage();
        rabbitTemplate.convertAndSend(
                msgTemplate.getExchange(),
                msgTemplate.getRoutingKey(),
                message
        );
    }
}
